#! /bin/sh
#############################################################################
# Licensed Materials - Property of IBM
#
# Governed under the terms of the International
# License Agreement for Non-Warranted Sample Code.
#
# (C) COPYRIGHT International Business Machines Corp. 1995 - 2006
#  All Rights Reserved.
#
#  US Government Users Restricted Rights - Use, duplication or
#  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#############################################################################
# SCRIPT: bldmc
# Builds Solaris CLI multi-connection applications
# Requires a second database: <alias2>. Suggested name: sample2
# Besides <prog_name>, requires embedded SQL files: <prog_name1> for binding
# to the first database, and <prog_name2> for binding to the second database.

if (test $# -lt 3)
then
  echo "Usage: bldmc <prog_name> <alias1> <alias2> [ <uid1> <pwd1> <uid2> <pwd2> ]"
    exit
fi

# Set DB2PATH to where DB2 will be accessed.
# The default is the standard instance path.
DB2PATH=$HOME/sqllib

bitwidth=64

# Uncomment the following line to compile 32-bit applications
#bitwidth=32

arch=`uname -p`
if [ $arch = "i386" ];
then
  if [ $bitwidth = "64" ];
  then
    CFLAG_ARCH=amd64
    LIB=lib64
  else
    CFLAG_ARCH=sse2
    LIB=lib32
  fi
else
  if [ $bitwidth = "64" ];
  then
    CFLAG_ARCH=v9
    LIB=lib64
  else
    CFLAG_ARCH=v8plusa
    LIB=lib32
  fi
fi

# Set the runtime path.
# LD_LIBRARY_PATH will be followed instead of the runtime path unless
# you unset LD_LIBRARY_PATH first to allow the runtime path to be used.
EXTRA_LFLAG="-R$DB2PATH/$LIB"

# Precompile and bind the program files.
./embprep $11 $2 $4 $5
./embprep $12 $3 $6 $7

# Compile the program files.
cc -xarch=$CFLAG_ARCH -I$DB2PATH/include -c $1.c $11.c $12.c utilcli.c

# Link the program.
cc -xarch=$CFLAG_ARCH -mt -o $1 $1.o $11.o $12.o utilcli.o \
  -L$DB2PATH/$LIB $EXTRA_LFLAG -ldb2

